package com.haobo.service;

import com.haobo.dao.UserMapper;
import com.haobo.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Queue;

/**
 * ClassName:ServiceDemo
 * Package:com.haobo.service
 * Description:
 *
 * @Date:2021/6/2 17:02
 * @Author:haobo
 */
public class ServiceDemo {
    public static void main(String[] args) throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //接口没有实现  通过mybatis动态代理实现的
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = userMapper.findAll();
        User user = userMapper.findById(1);
        System.out.println(userList);
        System.out.println(user);
    }
}
